home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap5 / 5_7 / sub_c / submit.c < prev   
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.7 KB  |  114 lines

  1.  
  2. #include "parsehtm.h"
  3. #include <stdio.h>
  4. #ifndef strcasecmp
  5.  
  6. int (strcasecmp)(const char *s1,const char *s2)
  7. {
  8.     int returnValue = 1;
  9.     
  10.     if((NULL != s1)&&(NULL != s2))
  11.     {
  12.         char test1,test2;
  13.         
  14.         for(;;++s1,++s2)
  15.         {
  16.             test1 = tolower(*s1);
  17.             test2 = tolower(*s2);
  18.             
  19.             if(test1 != test2)
  20.             {
  21.                 returnValue = 
  22.                     ((test1 < test2) ? -1:+1);
  23.                 break;
  24.             }
  25.             else if(test1 == '\0')
  26.             {
  27.                 returnValue = 0;
  28.                 break;
  29.             }
  30.         }
  31.     }
  32.     else if((NULL == s1)&&(NULL == s2))
  33.     {
  34.         returnValue = 0;
  35.     }
  36.     
  37.     return returnValue;
  38. }
  39.  
  40. #endif
  41.  
  42.  
  43. void submitHandler(String ts,String as,String et,Dictionary td)
  44. {
  45.     String value = 0;
  46.     
  47.     value = dict_valueForKey(td,"TYPE");
  48.     
  49.     if(value && value->string)
  50.     {
  51.         if(!strcasecmp(value->string,"submit"))
  52.         {
  53.             value = dict_valueForKey(td,"NAME");
  54.                         
  55.             if(value)
  56.             {
  57.                 string_setStringValue(value,"submit");
  58.             }
  59.             else
  60.             {
  61.                 value = string_alloc(5);
  62.                 string_setStringValue(value,"submit");
  63.                 dict_setValueForKey(td, "NAME",value);
  64.             }
  65.             
  66.             value = dict_valueForKey(td,"VALUE");
  67.                         
  68.             if(value)
  69.             {
  70.                 string_setStringValue(value,"Form was Run");
  71.             }
  72.             else
  73.             {
  74.                 value = string_alloc(5);
  75.                 string_setStringValue(value,"Form was Run");
  76.                 dict_setValueForKey(td, "VALUE",value);
  77.             }
  78.         }
  79.         
  80.     }
  81.     
  82.     value = stringForTagDict(td);
  83.     
  84.     if(value)
  85.     {
  86.         string_setStringValue(ts,value->string);
  87.     
  88.         string_free(value);
  89.     }
  90. }
  91.  
  92. void main(int argc, char *argv[])
  93. {
  94.     String output;
  95.     
  96.     initializeHtmlParsingLibrary();
  97.     
  98.     dict_setValueForKey(handlerDict,"INPUT",submitHandler);
  99.  
  100.     output = parseHtml("sub_c.htm");
  101.     
  102.     if(output && output->string)
  103.     {
  104.         printf("Content-type: text/html\n\n");
  105.         fwrite(output->string,sizeof(char),strlen(output->string),stdout);
  106.         printf("\n");
  107.         
  108.         string_free(output);
  109.     }
  110.     
  111.     exit(0);
  112. }
  113.  
  114.